home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Lines Curves and Area Fills / PolyEllipse / PolyEllipse.cs next >
Encoding:
Text File  |  2001-01-15  |  939 b   |  33 lines

  1. //------------------------------------------
  2. // PolyEllipse.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class PolyEllipse: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new PolyEllipse());
  13.      }
  14.      public PolyEllipse()
  15.      {
  16.           Text = "Ellipse with DrawLines";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           int      iNum = 2 * (cx + cy);
  21.           PointF[] aptf = new PointF[iNum];
  22.  
  23.           for (int i = 0; i < iNum; i++)
  24.           {
  25.                double dAng = i * 2 * Math.PI / (iNum - 1);
  26.  
  27.                aptf[i].X = (cx - 1) / 2f * (1 + (float)Math.Cos(dAng));
  28.                aptf[i].Y = (cy - 1) / 2f * (1 + (float)Math.Sin(dAng));
  29.           }
  30.           grfx.DrawLines(new Pen(clr), aptf);
  31.      }
  32. }
  33.